package com.fjrz.bbxwj.mode.manager

import com.module.lemlin.mode.SubscribeListener
import com.module.lemlin.rxhttp.subscribe
import com.fjrz.bbxwj.entity.UploadResponse
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.Disposable
import rxhttp.RxHttp
import rxhttp.wrapper.entity.Progress
import java.io.File

//公共接口

/**
 * 上传文件
 * @param file 文件
 * */
fun commonUpload(
    file: File, progress: UploadProgress? = null, listener: SubscribeListener<UploadResponse>
): Disposable = subscribe(
    RxHttp.postForm("/api/common/upload")
        .addFile("file", file)
        .upload(AndroidSchedulers.mainThread()) {
            progress?.onProgress(it)
        }
        .asClass(UploadResponse::class.java)
    , listener
)

interface UploadProgress {
    fun onProgress(progress: Progress)
}